from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from django.contrib.admin.widgets import AdminSplitDateTime
from django.forms.widgets import Media
from merengue.base.forms import BaseModelForm
from merengue.base.widgets import SplitDateTimeWidget


class SubscriptionTournamentForm(BaseModelForm):
    
    fieldsets = (
        (_('Player Data'), ('first_name', 'last_name', 'email', 'phone', 'gender', 'tshirt_size')),
        (_('Accomodation Data'), ('options', 'is_vegetarian', )),
        (_('Trip Data'), ('departure', 'departure_place', 'day_of_arrival', 'day_of_arrival_place', )),
        (_('Play level'), ('number_of_tournamets_played', 'year_played', 'score', 'team_position', )),
        ('', ('suggestions', )),
        )

    def __init__(self, *args, **kwargs):
        super(SubscriptionTournamentForm, self).__init__(*args, **kwargs)
        self.fields['departure'].widget = SplitDateTimeWidget()
        self.fields['day_of_arrival'].widget = SplitDateTimeWidget()
        self.fields['first_name'].label = _('Name')
        self.fields['last_name'].label = _('Surname')
        self.fields['departure_place'].label = _('Place:')
        self.fields['day_of_arrival_place'].label = _('Place:')
        self.fields['email'].label = _('E-mail')
        del self.fields['has_payed']
        del self.fields['want_a_disc']
        del self.fields['want_spanish_training']
        del self.fields['tshirt_size']

    def clean(self):
        cleaned_data = super(SubscriptionTournamentForm, self).clean()
        if self._errors.get('day_of_arrival') and not cleaned_data.get('day_of_arrival', None):
            del self._errors['day_of_arrival']
        if self._errors.get('departure') and not cleaned_data.get('departure', None):
            del self._errors['departure']
        return cleaned_data

    class Meta:
        from plugins.sportteam.models import SubscriptionTournament
        model = SubscriptionTournament

    class Media:
        extend = False
        js = (
            '/%s/jsi18n/' % settings.MERENGUE_URLS_PREFIX,
            settings.MEDIA_URL + "admin/js/core.js",
            settings.MEDIA_URL + "admin/js/calendar.js",
            settings.MEDIA_URL + "admin/js/admin/DateTimeShortcuts.js",
        )
        css = {
            'all': (settings.MEDIA_URL + 'merengue/css/event_calendar.css', ),
        }


